// https://leetcode-cn.com/problems/jump-game-ii/
// 45. 跳跃游戏 II

class Solution {
    public int jump(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int step = 0;
        int now_cover = 0;
        int next_cover = 0;
        for (int i = 0; i < nums.length; i++) {
            next_cover = Math.max(next_cover, i + nums[i]);
            if (i == now_cover) {
                if (now_cover != nums.length - 1) {
                    now_cover = next_cover;
                    step++;
                    if (next_cover >= nums.length - 1) {
                        break;
                    }
                } else {
                    break;
                }
            }
        }
        return step;
    }
}